<template>
  <div class="app-container">
    <div class="view-title">分享活动记录</div>
    <div class="add_box">
      <el-button type="warning" @click="handleExport">导出</el-button>
    </div>
    <div>
      <el-table :data="tableDataShare" style="width: 100%">
        <el-table-column prop="id" label="id" width="80"> </el-table-column>
        <el-table-column prop="user_id" label="用户id"> </el-table-column>
        <el-table-column prop="nick" label="用户昵称">
          <template slot-scope="scope">
            {{ scope.row.app_user.nick }}
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="用户手机号">
          <template slot-scope="scope">
            {{ scope.row.app_user.phone }}
          </template>
        </el-table-column>
        <el-table-column prop="level" label="用户等级">
          <template slot-scope="scope">
            {{ scope.row.app_user.level == "1" ? "合伙人" : "分销员" }}
          </template>
        </el-table-column>
        <el-table-column prop="share_points" label="当前积分">
          <template slot-scope="scope">
            {{ scope.row.app_user.share_points }}
          </template>
        </el-table-column>
        <el-table-column prop="new_user_id" label="新用户id"> </el-table-column>
        <el-table-column prop="new_user_phone" label="新用户手机号">
        </el-table-column>
        <el-table-column prop="is_help" label="助力状态">
          <template slot-scope="scope">
            <el-tag :type="scope.row.is_help == 0 ? 'info' : 'success'">
              {{ scope.row.is_help == 0 ? "未助力" : "已助力" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间"> </el-table-column>
      </el-table>
    </div>
    <div class="page_box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryParams.pageNow"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import {
  getShareActiveRecordList,
  exportShareActiveRecordList,
} from "@/api/shareActivity";
export default {
  data() {
    return {
      queryParams: {
        pageNow: 1,
        pageSize: 10,
      },
      total: null,
      tableDataShare: [],
    };
  },
  mounted() {
    this.getShareActiveRecordList();
  },
  methods: {
    // 导出
    handleExport() {
      this.exportShareActiveRecordList();
    },

    // 导出接口
    exportShareActiveRecordList() {
      exportShareActiveRecordList().then((res) => {
        if (res.code == 1) {
          location.href = res.data;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 获取列表借口
    getShareActiveRecordList() {
      getShareActiveRecordList({
        key: "TAxz1kTK0TLAGGMaznkFoLL0mcPYx8nH",
        page_now: this.queryParams.pageNow,
        page_size: this.queryParams.pageSize,
      }).then((res) => {
        if (res.code == 1) {
          this.tableDataShare = res.data;
          this.total = res.page_info.total_count;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 分页
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.queryParams.pageNow = 1;
      this.getShareActiveRecordList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageSize = 10;
      this.queryParams.pageNow = val;
      this.getShareActiveRecordList();
    },
  },
};
</script>
<style scoped lang="scss"></style>
